using System;
using System.Collections.Generic;
using System.Text;
using Wrath.Xml;
using System.Drawing;
using Wrath.Xml.Objects;

namespace Wrath.RuleForge
{
    public static class CurrentRuleSet
    {
        private static string name;

        public static string Name
        {
            get { return name; }
            set
            {
                name = value;
                if (String.IsNullOrEmpty(name))
                {
                    path = null;
                    frames = null;
                    icons = null;
                }
                else
                {
                    path = Globals.FantasyGroundsPaths.RuleSets + "\\" + name;
                    frames = new Dictionary<string, Element>();
                    icons = new Dictionary<string, Element>();
                }
            }
        }

        private static string path;

        public static string Path
        {
            get { return path; }
            set
            {
                path = value;
                if (String.IsNullOrEmpty(path))
                {
                    name = null;
                    frames = null;
                    icons = null;
                }
                else
                {
                    name = System.IO.Path.GetFileName(path);
                    frames = new Dictionary<string, Element>();
                    icons = new Dictionary<string, Element>();
                }
            }
        }

        private static Dictionary<string, Element> frames;

        public static Dictionary<string, Element> Frames
        {
            get { return frames; }
        }

        private static Dictionary<string, Element> icons;

        public static Dictionary<string, Element> Icons
        {
            get { return icons; }
        }

        private static Dictionary<string, Element> templates;

        public static Dictionary<string, Element> Templates
        {
            get { return templates; }
            set { templates = value; }
        }	

        static CurrentRuleSet()
        {
            name = null;
            path = null;
            frames = new Dictionary<string, Element>();
            icons = new Dictionary<string, Element>();
            templates = new Dictionary<string, Element>();
        }

        public static Image GetFrameImage(string frameName)
        {
            if (frameName == null) return null;

            Element frameElement = null;
            try { frameElement = frames[frameName]; }
            catch { frameElement = null; }

            if (frameElement == null) return null;
            
            Image frameImage = null;

            FrameDefinition frameDef = new FrameDefinition(frameElement);

            frameImage = Image.FromFile(CurrentRuleSet.Path + "\\" + frameDef.Bitmap.Replace('/', '\\'));

            return frameImage;
        }

    }
}
